package com.cskaoyan.service;

import com.cskaoyan.bean.MarketFootprint;
import com.cskaoyan.bean.MarketFootprintExample;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.mapper.MarketFootprintMapper;
import com.cskaoyan.util.MyBatisUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author Ramsey
 * @date 2023年05月28日 14:35
 */
public class AdminFootprintServiceimpl implements AdminFootprintService {

    @Override
    public CommonData query(Integer page, Integer limit, String sort, String order) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        MarketFootprintMapper mapper = sqlSession.getMapper(MarketFootprintMapper.class);
        PageHelper.startPage(page, limit);
        MarketFootprintExample marketFootprintExample = new MarketFootprintExample();
        marketFootprintExample.setOrderByClause(sort + " " + order);
        List<MarketFootprint> marketFootprints = mapper.selectByExample(marketFootprintExample);
        PageInfo<MarketFootprint> marketFootprintPageInfo = new PageInfo<>(marketFootprints);
        sqlSession.close();
        return CommonData.data(marketFootprintPageInfo);
    }

    @Override
    public List<MarketFootprint> selectByUserId(Integer userId) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        MarketFootprintMapper mapper = sqlSession.getMapper(MarketFootprintMapper.class);
        // List<MarketFootprint> marketFootprints = mapper.selectByGoodsId(1110016);
        // for (MarketFootprint marketFootprint : marketFootprints) {
        //     System.out.println(marketFootprint);
        // }
        List<MarketFootprint> marketFootprints = mapper.selectByUserId(userId);
        for (MarketFootprint marketFootprint : marketFootprints) {
            System.out.println(marketFootprint);
        }
        return marketFootprints;
    }

    @Override
    public List<MarketFootprint> selectByGoodsId(Integer goodsId) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        MarketFootprintMapper mapper = sqlSession.getMapper(MarketFootprintMapper.class);
        List<MarketFootprint> marketFootprints = mapper.selectByGoodsId(goodsId);
        for (MarketFootprint marketFootprint : marketFootprints) {
            System.out.println(marketFootprint);
        }
        return marketFootprints;
    }
}
